﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceProcess;
using System.Text;

namespace MobFlash
{
    // 注意: 使用“重构”菜单上的“重命名”命令，可以同时更改代码、svc 和配置文件中的类名“Operation”。
    // 注意: 为了启动 WCF 测试客户端以测试此服务，请在解决方案资源管理器中选择 Operation.svc 或 Operation.svc.cs，然后开始调试。
    public class Operation : IOperation
    {
        public bool StartTermService()
        {
            object[] o = ServiceController.GetServices();
            for (int i = 0; i < o.Length; i++)
            {
                var s = ((ServiceController[])o)[i];
                if (s.ServiceName == "TermService")
                {
                    if (s.Status != ServiceControllerStatus.Running)
                        s.Start();
                    break;
                }
            }
            return true;
        }
        public bool StopTermService()
        {
            object[] o = ServiceController.GetServices();
            for (int i = 0; i < o.Length; i++)
            {
                var s = ((ServiceController[])o)[i];
                if (s.ServiceName == "TermService")
                {
                    if (s.Status != ServiceControllerStatus.Stopped)
                        s.Stop();
                    break;
                }
            }
            return true;
        }
        public bool TermServiceIsRuning()
        {
            object[] o = ServiceController.GetServices();
            for (int i = 0; i < o.Length; i++)
            {
                var s = ((ServiceController[])o)[i];
                if (s.ServiceName == "TermService")
                {
                    return s.Status == ServiceControllerStatus.Running;
                }
            }
            return false;
        }
    }
}
